<?php 
 include_once dirname(__FILE__)."/config.php";
 class etat_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_code_etat;
		 protected $_decision;
		 protected $_code_ue;
		 protected $_date_decision;
		 public function get_name_table(){ return "etat";}
		 public function get_name_code_etat(){ return "code_etat";}
		 public function get_name_decision(){ return "decision";}
		 public function get_name_code_ue(){ return "code_ue";}
		 public function get_name_date_decision(){ return "date_decision";}
		 public function set_code_etat($parametre){  $this->_code_etat=$parametre;}	
		 public function set_decision($parametre){  $this->_decision=$parametre;}	
		 public function set_code_ue($parametre){  $this->_code_ue=$parametre;}	
		 public function set_date_decision($parametre){  $this->_date_decision=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_code_etat(){ return $this->_code_etat;}
		 public function get_decision(){ return $this->_decision;}
		 public function get_code_ue(){ return $this->_code_ue;}
		 public function get_date_decision(){ return $this->_date_decision;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 etat(
			decision,
			code_ue,
			date_decision)
 VALUES(
			'".$this->_decision."',
			'".$this->_code_ue."',
			'".$this->_date_decision."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_decision)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
decision='".$this->_decision."'";
}
if(!empty($this->_code_ue)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_ue='".$this->_code_ue."'";
}
if(!empty($this->_date_decision)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
date_decision='".$this->_date_decision."'";
}
$sql="UPDATE 
etat SET 
 ".$sql."
								WHERE code_etat ='".$this->_code_etat."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
etat 
 
									WHERE code_etat ='".$this->_code_etat."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
etat ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		code_etat,
		decision,
		code_ue,
		date_decision
 FROM 
 etat";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_code_etat=$row->code_etat;
		$this->_decision=$row->decision;
		$this->_code_ue=$row->code_ue;
		$this->_date_decision=$row->date_decision;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>